import {ThunkAction} from "redux-thunk";
import {RootState} from "../store";

export const GET_LOGIN = 'GET_LOGIN'

function waitRandom(): Promise<void> {
  return new Promise(resolve => {
    setTimeout(() => resolve(), (Math.random() + 1) * 1000 * 5)
  })
}

export interface ILoginAction {
  type: typeof GET_LOGIN
}

export const getLogin = (): ThunkAction<void, RootState, unknown, ILoginAction> => {
  return async dispatch => {
    await waitRandom();
    dispatch({
      type: "GET_LOGIN"
    })
  }
}
